FROM php:8.3-cli-alpine

# 使用阿里云镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# 安装依赖
RUN apk add --no-cache --virtual .build-deps \
    autoconf build-base pcre-dev linux-headers \
    && apk add --no-cache \
    git unzip libzip-dev postgresql-dev curl-dev \
    zlib-dev libxml2-dev oniguruma-dev openssl-dev brotli-dev \
    # 安装 PHP 扩展
    && docker-php-ext-install pdo pdo_mysql zip bcmath sockets ftp \
    # 安装 Redis 扩展
    && pecl install redis \
    && docker-php-ext-enable redis \
    # swoole
    && pecl install -D 'enable-sockets="no" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="no" enable-swoole-curl="yes" enable-cares="yes"' swoole-5.1.7 \
    && docker-php-ext-enable swoole \
    # 清理构建依赖
    && apk del .build-deps \
    && rm -rf /tmp/pear

# 安装 Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN chmod +x /usr/bin/composer

# 拷贝配置（可选）
COPY php.ini* /usr/local/etc/php/conf.d/

# 设置工作目录
WORKDIR /var/www/html

EXPOSE 30000
# 默认命令
CMD ["sh"]
